﻿/*
 * 创建者:  ideapadqiao\qiaojianhui
 * 邮件:    qiaojianhui@cont.com.cn
 * 功能描述: 
 * 历史记录: created by qiaojianhui 2012/2/26 11:55:28  
 *           
 */

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace oqis.core.config
{
    public class ConfigIniFile
    {
        #region 类属性

        /// <summary>
        /// 路径
        /// </summary>
        public string FilePath { get; set; }

        #endregion

        #region 方法

        /// <summary>
        /// INIFile Constructor.
        /// </summary>
        /// <param name="INIPath"></param>
        public ConfigIniFile(string iniPath) { this.FilePath = iniPath; }
      
        /// <summary>
        /// Write Data to the INI File
        /// </summary>
        /// <param name="section">Section name</param>
        /// <param name="key">Key Name</param>
        /// <param name="value">Value Name</param>
        public void SetValue(string section, string key, string value) { WritePrivateProfileString(section, key, value, this.FilePath); }

        /// <summary>
        /// Read Data Value From the Ini File
        /// </summary>
        /// <param name="section"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public string GetValue(string section, string key)
        {
            StringBuilder temp = new StringBuilder(255);
            int i = GetPrivateProfileString(section, key, "", temp, 255, this.FilePath);
            return temp.ToString();

        }

        #endregion

        #region WindowsAPI

        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
        
        #endregion
    }
}
